.class public Lorg/microemu/cldc/https/Connection;
.super Lorg/microemu/cldc/http/Connection;
.source "Connection.java"

# interfaces
.implements Ljavax/microedition/io/HttpsConnection;


# instance fields
.field private securityInfo:Ljavax/microedition/io/SecurityInfo;

.field private sslContext:Ljavax/net/ssl/SSLContext;


# direct methods
.method public constructor <init>()V
    .locals 2

    .prologue
    .line 47
    invoke-direct {p0}, Lorg/microemu/cldc/http/Connection;-><init>()V

    .line 49
    :try_start_0
    const-string v1, "SSL"

    invoke-static {v1}, Ljavax/net/ssl/SSLContext;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/SSLContext;

    move-result-object v1

    iput-object v1, p0, Lorg/microemu/cldc/https/Connection;->sslContext:Ljavax/net/ssl/SSLContext;
    :try_end_0
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0

    .line 54
    :goto_0
    const/4 v1, 0x0

    iput-object v1, p0, Lorg/microemu/cldc/https/Connection;->securityInfo:Ljavax/microedition/io/SecurityInfo;

    .line 55
    return-void

    .line 50
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 51
    .local v0, ex:Ljava/security/NoSuchAlgorithmException;
    invoke-static {v0}, Lorg/microemu/log/Logger;->error(Ljava/lang/Throwable;)V

    goto :goto_0
.end method


# virtual methods
.method public getPort()I
    .locals 3

    .prologue
    const/4 v2, -0x1

    .line 92
    iget-object v1, p0, Lorg/microemu/cldc/https/Connection;->cn:Ljava/net/URLConnection;

    if-nez v1, :cond_0

    move v1, v2

    .line 99
    :goto_0
    return v1

    .line 95
    :cond_0
    iget-object v1, p0, Lorg/microemu/cldc/https/Connection;->cn:Ljava/net/URLConnection;

    invoke-virtual {v1}, Ljava/net/URLConnection;->getURL()Ljava/net/URL;

    move-result-object v1

    invoke-virtual {v1}, Ljava/net/URL;->getPort()I

    move-result v0

    .line 96
    .local v0, port:I
    if-ne v0, v2, :cond_1

    .line 97
    const/16 v1, 0x1bb

    goto :goto_0

    :cond_1
    move v1, v0

    .line 99
    goto :goto_0
.end method

.method public getProtocol()Ljava/lang/String;
    .locals 1

    .prologue
    .line 82
    const-string v0, "https"

    return-object v0
.end method

.method public getSecurityInfo()Ljavax/microedition/io/SecurityInfo;
    .locals 7
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 58
    iget-object v2, p0, Lorg/microemu/cldc/https/Connection;->securityInfo:Ljavax/microedition/io/SecurityInfo;

    if-nez v2, :cond_3

    .line 59
    iget-object v2, p0, Lorg/microemu/cldc/https/Connection;->cn:Ljava/net/URLConnection;

    if-nez v2, :cond_0

    .line 60
    new-instance v2, Ljava/io/IOException;

    invoke-direct {v2}, Ljava/io/IOException;-><init>()V

    throw v2

    .line 62
    :cond_0
    iget-boolean v2, p0, Lorg/microemu/cldc/https/Connection;->connected:Z

    if-nez v2, :cond_1

    .line 63
    iget-object v2, p0, Lorg/microemu/cldc/https/Connection;->cn:Ljava/net/URLConnection;

    invoke-virtual {v2}, Ljava/net/URLConnection;->connect()V

    .line 64
    const/4 v2, 0x1

    iput-boolean v2, p0, Lorg/microemu/cldc/https/Connection;->connected:Z

    .line 66
    :cond_1
    iget-object v1, p0, Lorg/microemu/cldc/https/Connection;->cn:Ljava/net/URLConnection;

    check-cast v1, Ljavax/net/ssl/HttpsURLConnection;

    .line 68
    .local v1, https:Ljavax/net/ssl/HttpsURLConnection;
    invoke-virtual {v1}, Ljavax/net/ssl/HttpsURLConnection;->getServerCertificates()[Ljava/security/cert/Certificate;

    move-result-object v0

    .line 69
    .local v0, certs:[Ljava/security/cert/Certificate;
    array-length v2, v0

    if-nez v2, :cond_2

    .line 70
    new-instance v2, Ljava/io/IOException;

    invoke-direct {v2}, Ljava/io/IOException;-><init>()V

    throw v2

    .line 72
    :cond_2
    new-instance v3, Lorg/microemu/cldc/SecurityInfoImpl;

    invoke-virtual {v1}, Ljavax/net/ssl/HttpsURLConnection;->getCipherSuite()Ljava/lang/String;

    move-result-object v4

    iget-object v2, p0, Lorg/microemu/cldc/https/Connection;->sslContext:Ljavax/net/ssl/SSLContext;

    invoke-virtual {v2}, Ljavax/net/ssl/SSLContext;->getProtocol()Ljava/lang/String;

    move-result-object v5

    new-instance v6, Lorg/microemu/cldc/CertificateImpl;

    const/4 v2, 0x0

    aget-object v2, v0, v2

    check-cast v2, Ljava/security/cert/X509Certificate;

    invoke-direct {v6, v2}, Lorg/microemu/cldc/CertificateImpl;-><init>(Ljava/security/cert/X509Certificate;)V

    invoke-direct {v3, v4, v5, v6}, Lorg/microemu/cldc/SecurityInfoImpl;-><init>(Ljava/lang/String;Ljava/lang/String;Ljavax/microedition/pki/Certificate;)V

    iput-object v3, p0, Lorg/microemu/cldc/https/Connection;->securityInfo:Ljavax/microedition/io/SecurityInfo;

    .line 78
    .end local v1           #https:Ljavax/net/ssl/HttpsURLConnection;
    .end local v0           #certs:[Ljava/security/cert/Certificate;
    :cond_3
    iget-object v2, p0, Lorg/microemu/cldc/https/Connection;->securityInfo:Ljavax/microedition/io/SecurityInfo;

    return-object v2
.end method
